home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_11.lha / 6_11 / arbint.h < prev    next >
Text File  |  1993-08-08  |  3KB  |  97 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  6. * The C++ Answer Book */
  7. * Tony Hansen */
  8. * All rights reserved. */
  9. *
  10. arbitrary precision arithmetic
  11. Exercise 6.11
  12.  
  13.    All numbers are stored in an array of
  14.    unsigned shorts in two's complement format.
  15.    Its length is all maintained separately.
  16. /
  17. ifndef ARBINT_H
  18. define ARBINT_H
  19.  
  20.  include <stream.h>
  21.  include <minmax.h>
  22.  include <string.h>
  23.  include <error.h>
  24.  
  25. ypedef unsigned short ARB_type;
  26. ypedef unsigned long ARB_Ltype;
  27. onst ARB_Ltype ARB_base = 0x10000;
  28.  
  29. lass arbint
  30.  
  31.    struct arep
  32. {
  33. ARB_type *value;    // ptr to value
  34. int length;        // length of data
  35. int refcnt;        // reference count
  36. };
  37.  
  38.    arep *p;            // ptr to data
  39.  
  40.    arbint(ARB_type*,int);    /* DELETE */
  41.    friend void dodivmod(const arbint&,        /* DELETE */
  42. const arbint&, arbint&, arbint&);    /* DELETE */
  43. include "6_11a.h"        /* DELETE isneg() */
  44. include "6_11b.h"        /* DELETE arb_cmp() */
  45.  
  46. ublic:
  47.    arbint();                 // arbint x; or
  48.                  // new arbint;
  49.    ~arbint();                 // delete arbint;
  50.  
  51.    arbint(arbint&);             // arbint x = y;
  52.    arbint(long);             // arbint x = 35L;
  53.    arbint(unsigned long);         // arbint x = 35LU;
  54.    arbint(double);             // arbint x = 35.0;
  55.  
  56.    arbint& operator=(arbint&);         // x = y;
  57.    arbint& operator=(long);         // x = 35L;
  58.    arbint& operator=(unsigned long);// x = 35LU;
  59.    arbint& operator=(double);         // x = 35.0;
  60.  
  61.    friend arbint operator+
  62. (const arbint&, const arbint&);
  63.    friend arbint operator-
  64. (const arbint&, const arbint&);
  65.    friend arbint operator*
  66. (const arbint&, const arbint&);
  67.    friend arbint operator/
  68. (const arbint&, const arbint&);
  69.    friend arbint operator%
  70. (const arbint&, const arbint&);
  71.    friend arbint operator+
  72. (const arbint&);
  73.    friend arbint operator-
  74. (const arbint&);
  75.  
  76.    friend int operator==
  77. (const arbint&, const arbint&);
  78.    friend int operator!=
  79. (const arbint&, const arbint&);
  80.    friend int operator<
  81. (const arbint&, const arbint&);
  82.    friend int operator>=
  83. (const arbint&, const arbint&);
  84.    friend int operator>
  85. (const arbint&, const arbint&);
  86.    friend int operator<=
  87. (const arbint&, const arbint&);
  88.  
  89.    friend ostream& operator<<
  90. (ostream&, const arbint&);
  91.    friend istream& operator>>
  92. (istream&, arbint&);
  93. ;
  94.                                         // DELETE
  95. xtern void outputarb(ostream &out, char *h, ARB_type *s, int len, int ref = -100);    // DELETE
  96. endif /* ARBINT_H */
  97.